﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace ConstellationShow.Pages
{
    public partial class Setting : MyPage
    {
        static bool isload = false;
        public Setting()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Setting_Loaded);
        }

        void Setting_Loaded(object sender, RoutedEventArgs e)
        {
            object oo = Com.GetSetting("skip");
            if (oo != null && (bool)oo)
            {
                toggleSwitch1.IsChecked = true;
                toggleSwitch1.Content = "开启";
            }

            object o = Com.GetSetting("cons");
            if (o != null && (o as List<Cons>).Count!=0)
            {
                List<Cons> lst = o as List<Cons>;
                string str = "";
                foreach (Cons c in lst)
                    str += c.name + "&";
                txt.Content = str.TrimEnd('&'); ;
            }
            else
            {
                txt.Content = "暂无关注";
            }
            isload = true;
        }

        private void toggleSwitch1_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!isload) return;
            object o = Com.GetSetting("cons");
            if (o == null || (o as List<Cons>).Count == 0)
            {
                MessageBox.Show("请至少选择一个关注的星座！");
                toggleSwitch1.IsChecked = false;
                return;
            }
            Com.SetSetting("skip", true);
            toggleSwitch1.Content = "开启";
        }

        private void toggleSwitch1_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            Com.SetSetting("skip", false);
            toggleSwitch1.Content = "关闭";
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/Collect.xaml", UriKind.Relative));
        }
    }
}